/* Copyright © 2010 LPRM
Universidade Federal do Espírito Santo - RNP-GT CWTools

This file is part of GW-Android.

GW-Android is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

GW-Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with GW-Android. If not, see <http://www.gnu.org/licenses/>. */
package br.ufes.cwtools.gw.android.components;

import java.util.ArrayList;

import android.os.Parcel;
import android.os.Parcelable;

public class RelatedComponent implements Parcelable {
	private String mTag;  // Tag do componente.
	private String mLabel;  // Label para exibir este componente no menu de relacionamentos. 
	private String mRelatedExtra;  // Extra através do qual este componente se relaciona.
	
	public RelatedComponent(String tag, String label, String relatedExtra) {
		mTag = tag;
		mLabel = label;
		mRelatedExtra = relatedExtra;
	}

	public RelatedComponent(Parcel in) {
		mTag = in.readString();
		mLabel = in.readString();
		mRelatedExtra = in.readString();
	}
	
	public String getTag() {
		return mTag;
	}

	public String getLabel() {
		return mLabel;
	}

	public String getRelatedExtra() {
		return mRelatedExtra;
	}
	
	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(mTag != null ? mTag : "");
		dest.writeString(mLabel != null ? mLabel : "");
		dest.writeString(mRelatedExtra != null ? mRelatedExtra : "");
	}
	
	public static final Parcelable.Creator<RelatedComponent> CREATOR = new Parcelable.Creator<RelatedComponent>() {
		@Override
		public RelatedComponent createFromParcel(Parcel source) {
			return new RelatedComponent(source);
		}

		@Override
		public RelatedComponent[] newArray(int size) {
			return new RelatedComponent[size];
		}
	};
	
	public static ArrayList<RelatedComponent> filterRelatedComponents(ArrayList<RelatedComponent> relatedComponents, String relatedExtra) {
		final ArrayList<RelatedComponent> filtered = new ArrayList<RelatedComponent>();
		for (RelatedComponent related : relatedComponents) {
			if (related.getRelatedExtra().equals(relatedExtra)) {
				filtered.add(related);
			}
		}
		return filtered;
	}
}